var e = require("../../@babel/runtime/helpers/interopRequireDefault").default, t = e(require("../../kta/index")), a = e(require("../../api/api_YQYL_hf.js")), o = require("../../config/Links"), n = require("../../utils/YQYL"), i = [ null, "uncomplete", "complete", "failure" ], s = 1;

t.default.Page({
    data: {
        activity_info: {},
        check_id_card: !1,
        shareUrl: "",
        imgBaseUrl: o.imageBaseUrl.YQYL_hf,
        tabIndex: "1",
        common_rewards: [],
        showList: [],
        phone: "",
        achieve_goal_rewards: {},
        able_to_receive: !1,
        red_packet_daily_limit: !1,
        modal: !1,
        cancelText: "",
        modalText: "",
        time: 0,
        showPoster: !1,
        poster: null,
        postUtil: {
            handleSharePoster: function() {}
        }
    },
    onShareAppMessage: function() {
        return (0, n.handleShare)(this, "hf");
    },
    onLoad: function(e) {
        var t = this;
        (0, n.initPage)(this, e, "hf").then(function() {
            Promise.all([ "uncomplete", "complete", "failure" ].map(function(e) {
                return a.default.getRecordList(1, e);
            })).then(function(e) {
                0 !== e.map(function(e) {
                    return e.result.common_rewards;
                }).flat().length && t.setData({
                    showModal: !0
                });
            });
        });
    },
    onShow: function() {
        this.fetchList();
    },
    fetchList: function() {
        var e = this;
        wx.showLoading({
            title: "加载中"
        }), a.default.getRecordList(s, i[this.data.tabIndex]).then(function(t) {
            var a = t.result, o = a.achieve_goal_rewards, n = a.common_rewards, i = a.phone;
            e.setData({
                common_rewards: n,
                phone: i,
                achieve_goal_rewards: o[0],
                showList: n.slice(0, 10 * s)
            }), wx.hideLoading();
        });
    },
    loadMore: function() {
        10 * s < this.data.common_rewards.length && (s++, this.setData({
            showList: this.data.common_rewards.slice(0, 10 * s)
        }));
    },
    onChange: function(e) {
        this.setData({
            timeData: e.detail
        });
    },
    changeTab: function(e) {
        var t = this, a = e.currentTarget.dataset.index;
        s = 1, this.setData({
            tabIndex: a
        }, function() {
            t.fetchList();
        });
    },
    handlePoster: function() {
        this.data.poster ? this.setData({
            showPoster: !0
        }) : this.data.postUtil.handleSharePoster("record");
    },
    showModal: function(e) {
        var t = this, o = e.currentTarget.dataset.type;
        if ("illegal" === o) wx.showModal({
            content: "订单信息发生变更，无法领取话费，敬请谅解",
            showCancel: !1,
            confirmText: "确定"
        }); else if ("charge_illegal" === o) wx.showModal({
            content: "首充不足50元，无法领取",
            showCancel: !1,
            confirmText: "确定"
        }); else if ("same_user" === o) wx.showModal({
            content: "受邀人为本人，领取失败！",
            showCancel: !1,
            confirmText: "确定"
        }); else {
            if ("charge" === o) {
                var n = e.currentTarget.dataset.id;
                a.default.getHF(n).then(function() {
                    wx.showModal({
                        content: "话费已成功赠送至 账号".concat(t.data.phone, "中，请您查收！"),
                        showCancel: !1,
                        confirmText: "知道啦"
                    }), t.fetchList();
                }).catch(function() {
                    wx.showModal({
                        content: "微信异常，话费发放失败",
                        showCancel: !1,
                        confirmText: "确定"
                    });
                });
            }
            "100" === o && a.default.getHF().then(function() {
                wx.showModal({
                    content: "话费已成功赠送至 账号".concat(t.data.phone, "中，请您查收！"),
                    showCancel: !1,
                    confirmText: "确定"
                }), t.fetchList();
            }).catch(function() {
                wx.showModal({
                    content: "微信异常，话费发放失败",
                    showCancel: !1,
                    confirmText: "确定"
                });
            });
        }
    },
    closeModal: function() {
        this.setData({
            modal: !1,
            modalText: ""
        });
    },
    closePoster: function() {
        this.setData({
            showPoster: !1
        });
    },
    copyKeyword: function() {
        wx.setClipboardData({
            data: "我的历史邀请记录"
        }), this.closeModal();
    }
});